home *** CD-ROM | disk | FTP | other *** search
/ PCMania 75 / PCMania CD75_1.iso / lycos / netscape / netcast.z / ncjs10.jar / selector.js < prev    next >
Text File  |  1997-11-26  |  12KB  |  502 lines

  1. // (c) Copyright 1997 Netscape Communications, Corp.
  2.  
  3. var gNumLayers     = document.layers.length;
  4. var layerLevel       = null;
  5. var statusLocked   = false;
  6. var enablePopups    = 0;
  7. var propID          = null;
  8.  
  9. var expandedLayer    = null;
  10. var numContainers     = 0;
  11. var currentHeight    = 0;
  12.  
  13. var currentItem         = null;
  14.  
  15. var newWorld         = 1;
  16.  
  17. function onload()
  18. {
  19.     var startup=1;
  20.  
  21.     new LayerManager(window);
  22.  
  23.     captureEvents (Event.CLICK);
  24.     window.onClick = itemPopupMenu;
  25.  
  26.     depth.onmousedown = itemPopupMenu;
  27. }
  28.  
  29. function onblur()
  30. {
  31.     hideMenu();
  32. }
  33.  
  34. function finishLoading()
  35. {
  36.     var ready = parent.titlebar.document.demo.isSelectorReady();
  37.  
  38.     if (!ready) {
  39.         setTimeout(finishLoading, 750);
  40.         return;
  41.     }
  42.  
  43.     var    lastOpened = "" + depth.GetNetscapePref("netcaster.drawer.lastOpen", "finder", false);
  44.  
  45.     toggleContainer(lastOpened);
  46.  
  47.  
  48. }
  49.  
  50. function setFocusedItem(dataItem)
  51. {
  52.     currentItem = dataItem;
  53. }
  54.  
  55. function layerLoaded(layerObj, parameter)
  56. {
  57.     layerObj.fontFace = "arial,geneva,helvetica";
  58.     layerObj.fontSize = "+0";
  59.     layerObj.y        = currentHeight;
  60.     layerObj.type     = parameter.getType();
  61.     layerObj.itemName = parameter.getItemName();
  62.     layerObj.descName = parameter.getDescription();
  63.     layerObj.url      = parameter.getURL();
  64.     layerObj.dataItem = parameter;
  65.     layerObj.clip.height = 30;
  66.     layerObj.clip.width = 200;
  67.  
  68.     parameter.setItemView(layerObj);
  69.  
  70.     currentHeight += 30;
  71.     layerObj.visibility = "show";
  72.  
  73. }
  74.  
  75. function createCategoryLayer(dataItem)
  76. {
  77.     var newLoadObj = new LayerLoadObject(null, "headtmpl.htm",
  78.         window, this, dataItem, false);
  79.  
  80.     window.layerManager.layerLoad(newLoadObj);
  81.     window.numContainers++;
  82.  
  83.     return;
  84. }
  85.  
  86. function contextCreateItemLayer(dataItem)
  87. {
  88.     setTimeout(createItemLayer, 10, dataItem);
  89. }
  90.  
  91. function createItemLayer(dataItem)
  92. {
  93.     var itemParent = dataItem.getParent();
  94.     var parentLayer = itemParent.getItemView();
  95.  
  96.     if (!parentLayer || (parentLayer == null) || parentLayer.container == null) {
  97.         setTimeout(createItemLayer, 200, dataItem);
  98.         return;
  99.     }
  100.  
  101.     var newLoadObj = new LayerLoadObject(null, "itemtmpl.htm",
  102.         parentLayer.container, parentLayer.container, dataItem, false);
  103.  
  104.     window.layerManager.layerLoad(newLoadObj);
  105.  
  106.     parentLayer.container.itemCount++;
  107.     return;
  108. }
  109.  
  110. function createPageLayer(dataItem, url)
  111. {
  112.     var itemParent = dataItem.getParent();
  113.     var parentLayer = itemParent.getItemView();
  114.  
  115.     if (!parentLayer || (parentLayer == null) || parentLayer.container == null) {
  116.         setTimeout(createPageLayer, 200, dataItem, url);
  117.         return;
  118.     }
  119.  
  120.     var newLoadObj = new LayerLoadObject(null, url,
  121.         parentLayer.container, parentLayer.container, dataItem, true);
  122.  
  123.     window.layerManager.layerLoad(newLoadObj);
  124.  
  125.     parentLayer.container.itemCount++;
  126.     return;
  127. }
  128.  
  129. function refreshItemLayer(dataItem, layer)
  130. {
  131.     layer.type     = dataItem.getType();
  132.     layer.itemName = dataItem.getItemName();
  133.     layer.descName = dataItem.getDescription();
  134.     layer.url      = dataItem.getURL();
  135.  
  136.     layer.refreshChannelInfo();
  137. }
  138.  
  139.  
  140.  
  141. function contextDeleteItemLayer(dataItem, layer)
  142. {
  143.     setTimeout(deleteItemLayer, 10, dataItem, layer);
  144. }
  145.  
  146. function deleteItemLayer(dataItem, layer)
  147. {
  148.     var    itemHeight = 30;
  149.     var    parentArray = layer.parentLayer.document.layers;
  150.  
  151.     layer.visibility = "hide";
  152.  
  153.     for (var i=0; i < parentArray.length; i++) {
  154.         if (parentArray[i].top > layer.top) {
  155.  
  156.             parentArray[i].top -= itemHeight;
  157.          }
  158.     }
  159.  
  160.     layer.parentLayer.topPos -= itemHeight;
  161. }
  162.  
  163. function openWebtopURL(siteURL, dataItem)
  164. {
  165.     parent.titlebar.OpenWebtop(siteURL, dataItem, true);
  166. }
  167.  
  168. function openSiteURL(fullscreen, siteURL)
  169. {
  170.     parent.titlebar.OpenSite(fullscreen, siteURL, true);
  171. }
  172.   
  173. function openCastanetURL(siteURL)
  174. {
  175.     parent.titlebar.document.demo.openCastanetURL(siteURL);
  176. }
  177.  
  178. function toggleContainer(containerName)
  179. {
  180.     var container =    null;
  181.     var containerLayer = null;
  182.  
  183.     if (containerName == null || containerName == "")
  184.         return;
  185.  
  186.     container = parent.titlebar.document.demo.findContainerByName(containerName)
  187.     if (container != null) {
  188.         containerLayer = container.getItemView()
  189.     }
  190.  
  191.     if (containerLayer == null) {
  192.         return;
  193.     }
  194.  
  195.     var parentArray = containerLayer.parentLayer.document.layers;
  196.  
  197.     if (expandedLayer == null) {
  198.         expandedLayer = containerLayer;
  199.         expandedLayer.clip.height = containerGetHeight() + 30;
  200.         expandedLayer.showContainer();
  201.  
  202.         for (var i=0; i < parentArray.length; i++) {
  203.             if (parentArray[i].top > expandedLayer.top) {
  204.                 parentArray[i].top += containerGetHeight();
  205.             }
  206.             
  207.             if (parentArray[i] != expandedLayer) {
  208.                 parentArray[i].clip.bottom = 30;
  209.             }
  210.         }
  211.     }
  212.  
  213.     else if (expandedLayer.top < containerLayer.top) {
  214.         var moveArray = new Array();
  215.         var    itemCount = 0;
  216.  
  217.         for (var i=0; i < parentArray.length; i++) {
  218.             if ((parentArray[i].top > expandedLayer.top) &&
  219.                 (parentArray[i].top <= containerLayer.top)) {
  220.                 moveArray[itemCount++] = parentArray[i];
  221.             }
  222.         }
  223.  
  224.         repositionContainers(-250, moveArray, expandedLayer, 30, containerLayer);
  225.  
  226.         expandedLayer.hiding();
  227.         expandedLayer = containerLayer;
  228.         containerLayer.showing();
  229.     }
  230.  
  231.     else if (expandedLayer.top > containerLayer.top) {
  232.         var moveArray = new Array;
  233.         var    itemCount = 0;
  234.         var parentArray = containerLayer.parentLayer.document.layers;
  235.  
  236.         for (var i=0; i < parentArray.length; i++) {
  237.             if ((parentArray[i].top > containerLayer.top) &&
  238.                 (parentArray[i].top <= expandedLayer.top)) {
  239.                 moveArray[itemCount++] = parentArray[i];
  240.             }
  241.         }
  242.  
  243.         var newBottom = containerGetHeight() + 30;
  244.         repositionContainers(250, moveArray, containerLayer, newBottom, expandedLayer);
  245.  
  246.         expandedLayer.hiding();
  247.         expandedLayer = containerLayer;
  248.         containerLayer.showing();
  249.     }
  250.  
  251. }
  252.  
  253. function repositionContainers(delta, moveArray, sourceLayer, sourceClip, destLayer)
  254. {
  255.     var bottom = sourceLayer.clip.height;
  256.  
  257.     if (((delta > 0) && (bottom < sourceClip)) ||
  258.         ((delta < 0) && (bottom > sourceClip))) {
  259.     
  260.         var pinnedDelta = Math.abs(bottom - sourceClip);
  261.  
  262.         if (Math.abs(delta) > pinnedDelta) {
  263.  
  264.             if (delta < 0) {
  265.                 pinnedDelta *= -1;
  266.             }
  267.  
  268.             delta = pinnedDelta;
  269.         }
  270.  
  271.  
  272.         for (var i=0; i < moveArray.length; i++) {
  273.             moveArray[i].top += delta;
  274.         }
  275.  
  276.         if (delta < 0) {
  277.             sourceLayer.clip.height += delta;
  278.         } else {
  279.             sourceLayer.clip.bottom += delta;
  280.         }
  281.  
  282.         destLayer.clip.height -= delta;
  283.  
  284.         if (sourceLayer.clip.height != sourceClip) {
  285.             setTimeout(repositionContainers, 40, delta, moveArray, sourceLayer, sourceClip, destLayer);
  286.         }
  287.  
  288.     }
  289.  
  290.     return;
  291. }
  292.  
  293. function handleProperties(item)
  294. {
  295.     if ( null != item ) 
  296.     {
  297.         editing = 1;
  298.         var propWin = depth.SecureWindowOpen (window, 'addc.htm', 
  299.                 'prefs', 
  300.                 'left=150,top=200,width=427,height=247,titlebar=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,modal=yes,alwaysRaised=yes,z-lock=no,dependent=yes,hotkeys=no');
  301.  
  302.         propWin.depth = depth;
  303.         propID = item;
  304.     }
  305. }
  306.  
  307. function PropertiesCallback(propsWindow)
  308. {
  309.     propsWindow.selector  = this;
  310.     propsWindow.container = depth.getDefaultContainer();
  311.  
  312.     if (editing == 1)
  313.         propsWindow.editItem(propID);
  314.  
  315.     propsWindow.callback = self;
  316.  
  317. }
  318.  
  319. function hiliteMenuItem(e) {
  320.     e.target.bgColor="#808080";
  321. }
  322.  
  323. function showMenu(dataItem, menuLeft, menuTop)
  324. {
  325.     var menu = window.document.layers['menu'];
  326.     var menuCommands = dataItem.getMenuItems();
  327.     var currentDoc = menu.layers['item_name'].document;
  328.  
  329.     menu.clip.height = ((menuCommands.length + 1) * 25) + 3;    // leave a 3 pixel margin
  330.     currentDoc.open("text/html");
  331.     currentDoc.write("<center><font size=-1 face='arial,helvetica'><b>");
  332.     currentDoc.write("" + dataItem.getItemName() + "</b></font></center>");
  333.     currentDoc.close();
  334.  
  335.     for (var i=0; i < menuCommands.length; i++) {
  336.         var currentDoc = menu.layers["item"+i].document;
  337.         currentDoc.open("text/html");
  338.         currentDoc.write("<font size=-1 face='arial,helvetica'>");
  339.         if (("" + menuCommands[i][0]) == "-") {
  340.             menu.layers["item"+i].onmouseover=null;
  341.             currentDoc.write("<hr width=80%></font>");
  342.         } else {
  343.             menu.layers["item"+i].onmouseover=hiliteMenuItem;
  344.             currentDoc.write("<spacer type=block height=2 width=200><spacer type=block height=1 width=5>");
  345.             currentDoc.write(menuCommands[i][0] + "</font>");
  346.             currentDoc.write("<layer top=0 left=0 clip=150,25>");
  347.             currentDoc.write("<a href='about:blank' " +
  348.                 "onclick='parentLayer.doMenuItem(\"" + menuCommands[i][1] + "\");return false;'>" +
  349.                 "<img src='images/blank.gif' border=none width=150 height=25>" +
  350.                 "</a></layer>");
  351.         }
  352.         currentDoc.close();
  353.     }
  354.  
  355.     menu.layers["item"+menuCommands.length].onmouseover=null;
  356.  
  357.     // the selector is 200 pixels wide
  358.     var overflow = menuLeft + menu.clip.width- 200;
  359.  
  360.     if (overflow > 0) {
  361.         menu.left = menuLeft - overflow;
  362.     } else {
  363.         menu.left = menuLeft;
  364.     }
  365.  
  366.     var overflow = menuTop + menu.clip.height - (containerGetHeight() + 30);
  367.     if (overflow > 0) {
  368.         menu.top = menuTop - overflow;
  369.     } else {
  370.         menu.top = menuTop;
  371.     }
  372.  
  373.     menu.visibility = "show";
  374.     menu.menuTarget = dataItem;
  375.     menu.zIndex=1000;
  376.  
  377. }
  378.  
  379. function hideMenu()
  380. {
  381.     var menu = window.document.layers['menu'];
  382.  
  383.     if (menu.visibility = "show") {
  384.         menu.visibility="hide";
  385.     }    
  386. }
  387.  
  388. function itemPopupMenu(e)
  389. {
  390.     var menu = window.document.layers['menu'];
  391.  
  392.     if (e.which > 1 || (depth.isMac() && (e.modifiers & Event.CONTROL_MASK)))
  393.     {
  394.         if (currentItem == null) {
  395.             menu.visibility = "hide";
  396.         } else {
  397.             setTimeout(showMenu, 10, currentItem, e.pageX, e.pageY);
  398.         }
  399.  
  400.         return false;
  401.     }
  402.     else
  403.     {
  404.         if (menu.visibility == "show") {
  405.  
  406.             if ((e.pageX >= menu.left) && (e.pageX <= (menu.left + menu.clip.width))
  407.                 && (e.pageY >= menu.top) && (e.pageY <= (menu.top + menu.clip.height))) {
  408.  
  409.                 menu.visibility = "hide";
  410.                 return routeEvent(e);
  411.             }
  412.  
  413.             menu.visibility = "hide";
  414.             return false;
  415.         }
  416.         
  417.         return routeEvent(e);
  418.     }
  419. }
  420.  
  421. function showError(error) {
  422.  if (error != null)
  423.     alert(error);
  424. }
  425.  
  426. function winOpen(url, name, options) {
  427.     return window.open(url, name, options);
  428. }
  429.  
  430. function winAlert(string) {
  431.     return window.alert(string);
  432. }
  433.  
  434. function winConfirm(string) {
  435.     return window.confirm(string);
  436. }
  437.  
  438. function winEscape(string) {
  439.     return window.escape(string);
  440. }
  441.  
  442. function winUnescape(string) {
  443.     return window.unescape(string);
  444. }
  445.  
  446. function containerIsOpen(containerName) {
  447.     return expandedContainer == containerName;
  448. }
  449.  
  450. function containerGetHeight() {
  451.     return window.innerHeight - (window.numContainers * 30);    
  452. }
  453.  
  454. function containerGetParameter(containerName) {
  455.     container = parent.titlebar.document.demo.findContainerByName(containerName)
  456.  
  457.     if (container != null) {
  458.         return "" + container.getUserData();
  459.     }
  460.  
  461.     return "";
  462. }
  463.  
  464. function containerSetParameter(containerName, data) {
  465.     container = parent.titlebar.document.demo.findContainerByName(containerName)
  466.     if (container != null) {
  467.         container.setUserData(data);
  468.     }
  469.  
  470.     return;
  471. }
  472.  
  473. function selectorOpen() {
  474.     parent.selectorTab.ShowSelector();
  475.     return;
  476. }
  477.  
  478. function selectorClose() {
  479.     parent.selectorTab.HideSelector();
  480.     return;
  481. }
  482.  
  483. function containerPrintln(outputString) {
  484.     java.lang.System.out.println(outputString);
  485.     return;
  486. }
  487.  
  488. export winOpen;
  489. export winAlert;
  490. export winConfirm;
  491. export winEscape;
  492. export winUnescape;
  493. export containerIsOpen;
  494. export containerGetHeight;
  495. export containerGetParameter;
  496. export containerSetParameter;
  497. export selectorClose;
  498. export selectorOpen;
  499. export containerPrintln;
  500.  
  501. void(0);
  502.